package EXam.Question13;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 有空再重做一个List的题，去翻视频跟着做也可以
 * 增强For循环遍历Map集合到底是什么
 */
public class BianliMap {
    public static void main(String[] args) {
        // 创建HashMap集合，键是宿舍号，值是宿舍里住的4个学生
        Map<String, List<EXam.Question13.Student>> dormitoryMap = new HashMap<>();

        // 创建第一个宿舍的学生
        List<EXam.Question13.Student> dorm1Students = new ArrayList<>();
        dorm1Students.add(new EXam.Question13.Student("张三", 18));
        dorm1Students.add(new EXam.Question13.Student("李四", 19));
        dorm1Students.add(new EXam.Question13.Student("王五", 18));
        dorm1Students.add(new EXam.Question13.Student("赵六", 20));

        // 创建第二个宿舍的学生
        List<EXam.Question13.Student> dorm2Students = new ArrayList<>();
        dorm2Students.add(new EXam.Question13.Student("小明", 19));
        dorm2Students.add(new EXam.Question13.Student("小红", 18));
        dorm2Students.add(new EXam.Question13.Student("小刚", 20));
        dorm2Students.add(new EXam.Question13.Student("小丽", 19));

        // 将宿舍和学生信息存入Map
        dormitoryMap.put("宿舍101", dorm1Students);
        dormitoryMap.put("宿舍102", dorm2Students);

        // 遍历Map集合，打印输出每一个宿舍住了哪些学生
        System.out.println("宿舍居住情况：");
        for (Map.Entry<String, List<EXam.Question13.Student>> entry : dormitoryMap.entrySet()) {
            String dormitoryNumber = entry.getKey();
            List<EXam.Question13.Student> students = entry.getValue();

            System.out.println(dormitoryNumber + "住的学生有：");
            for (EXam.Question13.Student student : students) {
                System.out.println("  " + student);
            }
            System.out.println(); // 空行分隔
        }
    }
}